package com.zhaoxianglong.priciple;

import org.junit.Test;

/**
 * @program: design-learning
 * @description: 开闭原则
 * @author: zhaoxianglong
 * @create: 2021-03-17 15:24
 **/
public class OcpTest {

    @Test
    public void test(){
        Plainting plainting = new Plainting();
        plainting.draw(new Rectangle());
        plainting.draw(new Circle());
    }
}

class Shape{
    int type;
    String shape;
}

class Rectangle extends Shape{
    Rectangle() {
        super.type = 1;
        super.shape = "矩形";
    }
}

class Circle extends Shape{
    Circle(){
        super.type = 2;
        super.shape = "圆形";
    }
}

class Plainting{
    public void draw(Shape s){
        System.out.println("绘制" + s.shape);
    }
}
